package com.atguigu.ssyx.product.service.impl;

import com.atguigu.ssyx.model.product.Category;
import com.atguigu.ssyx.product.mapper.CategoryMapper;
import com.atguigu.ssyx.product.service.CategoryService;
import com.atguigu.ssyx.vo.product.CategoryQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 杨林
 * @create 2023-07-19 10:49 星期三
 * description:
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
    
    @Autowired
    private CategoryMapper categoryMapper;

    /**
     * 分页查询商品列表
     * @param page
     * @param limit
     * @param categoryQueryVo
     * @return
     */
    @Override
    public IPage getPageList(Long page, Long limit, CategoryQueryVo categoryQueryVo) {
        //构建分页条件
        Page<Category> categoryPage = new Page<>(page, limit);
        //构建查询条件
        String name = categoryQueryVo.getName();
        LambdaQueryWrapper<Category> wrapper = new LambdaQueryWrapper<>();
        if (name != null){
         wrapper.like(Category::getName,name);   
        }
        Page<Category> pageModel = categoryMapper.selectPage(categoryPage, wrapper);
        return pageModel;
    }

    /**
     * 查询所有的商品信息
     * @return
     */
    @Override
    public List<Category> findAllList() {
        List<Category> list = categoryMapper.selectList(null);
        return list;
    }

    /**
     * 根据ids批量获取分类信息
     * @param categoryIds
     * @return
     */
    @Override
    public List<Category> findCategoryList(List<Long> categoryIds) {
        LambdaQueryWrapper<Category> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(Category::getId,categoryIds);
        List<Category> list = categoryMapper.selectList(wrapper);
        return list;
    }
}
